import Terminal as Terminal
import threading
from kafka import KafkaConsumer
import time

def start_send_test_msg(terminal):
    while True:
        hex_msg = 'F002' + '0110000001F0000001F0000002' + '0110000005F0000001F0000002'
        terminal.send_reainfo(0x02,0xFE,  bytearray.fromhex(hex_msg))

        hex_msg = 'F102' + '0110000001' + '0210000006'
        terminal.send_reainfo(0x02, 0xFE, bytearray.fromhex(hex_msg))

        time.sleep(1)
        
        

def start_terminal():
    t = Terminal.Terminal(host='172.16.8.91', port=5061, vin='LZGJL8888GG123215', iccid='POIUYTREQASGFGHJ8123')
    t.start()
    test_thread = threading.Thread(target=start_send_test_msg, args=([t]))
    #test_thread.start()

def read_kafka_msg():
    consumer = KafkaConsumer('REMOTE_CONTROL_TASK_STATUS_UPDATE',
                             bootstrap_servers=['172.16.8.91:9092'])
    for message in consumer:
        print("%s:%d:%d: key=%s value=%s" % (message.topic, message.partition,
                                             message.offset, message.key,
                                             message.value))

if __name__ == '__main__':
    terminal_thread = threading.Thread(target=start_terminal, args=())
    terminal_thread.start()
    read_kafka_msg()
